'use strict';

/**
 * copyright (c) 2017-2023 厦门风领科技有限公司
 * https://www.fengling.cn/
 * 
 * 初始化转场动画
 * zengbinsi
 * 2020-09-22
 */


import path from 'path';
import pathUtil from '../libs/utils/path-utils';
import fileUtil from '../libs/utils/file-utils';
import { callSequence } from '../libs/utils/function-call-seq';
const srcPath = pathUtil.getPathInTemplateAssets(path.join('bundles', 'ui', 'loading'));
const dstPath = pathUtil.getPathInAssets(path.join('bundles', 'ui', 'loading'));




// 初始化目录
const initDir = async (callback?: Function) => {
    console.log('[tool-box]创建目录', dstPath);
    pathUtil.mkPathSync(dstPath);
    fileUtil.copy(`${srcPath}.meta`, `${dstPath}.meta`);
    await pathUtil.refreshAsset(`db://assets/bundles/ui/loading/`);
    callback && callback();
};


export const initFileUITransition = (fileName: string, callback?: Function) => {
    console.log(`[tool-box]import FLoading${fileName}Panel...`);
    return callSequence([initDir, async (cb?: Function) => {
        fileUtil.copy(path.join(srcPath, `FLoading${fileName}Panel.ts`), path.join(dstPath, `FLoading${fileName}Panel.ts`));
        fileUtil.copy(path.join(srcPath, `FLoading${fileName}Panel.ts.meta`), path.join(dstPath, `FLoading${fileName}Panel.ts.meta`));
        fileUtil.copy(path.join(srcPath, `FLoading${fileName}Panel.prefab`), path.join(dstPath, `FLoading${fileName}Panel.prefab`));

        await pathUtil.refreshAsset(`db://assets/bundles/ui/loading/`);
        console.log(`[tool-box]import FLoading${fileName}Panel successed!`);
        cb && cb();
    }, callback]);
};